package com.libgdxbar.pvzlikegame.objects;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.libgdxbar.pvzlikegame.AssetsLoader;
import com.libgdxbar.pvzlikegame.entities.MoveableEntity;
import org.libgdxbar.projects.interfaces.renderer.IBatchRender;

public class SampleTextureZombie extends MoveableEntity implements IBatchRender {
	private final Texture texture = AssetsLoader.getInstance().get("zombie-stub.png", Texture.class);

	public SampleTextureZombie(float x, float y) {
		// 演示逻辑 创建随机方向移动的僵尸
		super(x, y, MathUtils.random(200f) + 200f, MathUtils.random(200f) + 200f);
	}

	@Override
	public void run(float delta) {
		super.run(delta);
		Vector2 position = getPosition();
		// 这里碰屏幕边缘反弹只是演示逻辑而已 实际请自己实现
		if (position.x > 640 - 50) setVelocityX(-Math.abs(getVelocityX()));
		if (position.x < 0) setVelocityX(Math.abs(getVelocityX()));
		if (position.y > 480 - 50) setVelocityY(-Math.abs(getVelocityY()));
		if (position.y < 0) setVelocityY(Math.abs(getVelocityY()));
	}

	@Override
	public void render(Batch batch) {
		Vector2 position = getPosition();
		batch.draw(texture, position.x, position.y, 50, 50);
	}
}
